/*******************************************************************************
 * Copyright (c) 2012 Daniele Parisi.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Daniele Parisi
 *     neb.inf@gmail.com
 *     http://www.danieleparisi.com/
 ******************************************************************************/
package org.jxreport.core.views.text;

import java.util.LinkedList;
import java.util.List;

import org.jxreport.core.Table;
import org.jxreport.core.XMLValues;
import org.jxreport.core.views.ViewObject;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class TextView extends ViewObject{

	protected List<String> paragraphs = new LinkedList<String>();

	public TextView(Element viewElement, Table table) {
		super(viewElement, table);

		NodeList nl = viewElement.getElementsByTagName(XMLValues.PARAGRAPH);
		for(int i = 0 ; i < nl.getLength();i++) {
			Element el = (Element)nl.item(i);
			this.paragraphs.add(el.getTextContent());
		}
	}
	
	public String getHTMLBodyCode() {
		String html = "";
		if(this.title != null) html += "<h2>" + this.title + "</h2>";
		for (String text : this.paragraphs)
			html += "<p>" + text + "</p>";

		return html;
	}

	public List<String> getParagraphs() {
		return paragraphs;
	}

	public void setParagraphs(List<String> paragraphs) {
		this.paragraphs = paragraphs;
	}
}
